from astro.continuum import spline_continuum,splice
import astro.spec as sp

if 1:
    filenames = ('/home/nhmc/data/williger_qsos/0041m2607.dat', 
                 '/home/nhmc/data/williger_qsos/0041m2638.dat', 
                 '/home/nhmc/data/williger_qsos/0041m2658.dat', 
                 '/home/nhmc/data/williger_qsos/0041m2707.dat', 
                 '/home/nhmc/data/williger_qsos/0042m2627.dat', 
                 '/home/nhmc/data/williger_qsos/0042m2639.dat',
                 '/home/nhmc/data/williger_qsos/0042m2656.dat',
                 '/home/nhmc/data/williger_qsos/0042m2657.dat', 
                 '/home/nhmc/data/williger_qsos/0042m2714.dat', 
                 '/home/nhmc/data/williger_qsos/0043m2633.dat') 

    spec  = [sp.read(f) for f in filenames]

    # a good fit outside the forest at these resolutions and S/N.

    co2 = spline_continuum(spec[0], 4300, spec[0].wa[-1], vwidth=1000,
                           nsig=0.7, resid_std=1.0)

    # a good fit inside the forest at there resolutions and S/N.
    co1 = spline_continuum(spec[0], spec[0].wa[0], 4300, vwidth=2500,
                           nsig=0.5, resid_std=1.0)

    ind = spec[0].wa_index(4300)
    co3 = splice(co1, co2, ind-20, ind+20)

